-
-
Notifications
You must be signed in to change notification settings - Fork 359
Add Computus in Javascript and Typescript #807
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Computus in Javascript and Typescript #807
Conversation
const a = year % 19; | ||
|
||
// Century index | ||
const k = Math.floor(year / 100); | ||
|
||
// Shift of metonic cycle, add a day offset every 300 years | ||
const p = Math.floor((13 + 8 * k) / 25); | ||
|
||
// Correction for non-observed leap days | ||
const q = Math.floor(k / 4); | ||
|
||
// Correction to starting point of calculation each century | ||
const M = mod(15 - p + k - q, 30); | ||
|
||
// Number of days from March 21st until the full moon | ||
const d = (19 * a + M) % 30; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason you aren't explicitly typing these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't explicitly type these variables to be clearer to read.
However, it may be better with types: if someone wants an implementation without types, they could use the JavaScript version.
I'll add types to every variable as soon as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great, thanks!
// Historical corrections for April 26 and 25 | ||
if (e === 6) if (d === 29 || (d === 28 && a > 10)) e = -1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you mind bringing the reassignment into its own line? It's a bit buried at the end as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I can fix that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, would you mind doing that for all instances of inline if/else
contents/computus/computus.md
Outdated
@@ -320,6 +320,10 @@ For now, we have the code outputting a tuple of $$d$$ and $$e$$, so users can us | |||
[import, lang:"lisp"](code/clisp/gauss-easter.lisp) | |||
{% sample lang="nim" %} | |||
[import, lang:"nim"](code/nim/gauss_easter.nim) | |||
{% sample lang="javascript" %} | |||
[import, lang:"nim"](code/javascript/gauss_easter.js) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll also need to change the lang "variable" to JavaScript and TypeScript. I forgot to do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great catch, I missed this as well
I added types to the typescript code and changed the formatting for javascript and typescript. |
I think you're trying to go a little too fast with the PRs. 😅 |
Since you are a first time contributor, feel free to add your name to the list in CONTRIBUTORS.md. Also: Dart seems to be a new language in the AAA, could you add a section to the book.json and make sure syntax highlighting is correct? It should be, but it would be nice to double-check! |
For this PR, the implementation is so straightforward, that I feel it is ok to merge Dart as long as it produces the right results; however, definitely split it in future PRs. Thanks again for the submission! |
Note still needs lang highlighting for dart like #839 book.json |
c17ed01
to
48b52eb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If @ntindle is okay with it, I think it's okay with me.
I added my name to the Also, About the Dart implementation, I could have created another PR. Sorry about that. |
Right, I think we didn't consider Windows' path system. From manual inspection, it looks like they are the same images, though, so I don't think it's that much of a problem. We'll have to see what breaks, and make sure there are no case-dependant paths in the AAA any more for future-proofing it. Maybe you could open an issue and/or a PR to correct the name conflict problem, if you feel like it. It would be appreciated. 😉 |
It seems the only file referencing this image is |
A translation of the computus Julia code in javascript and in typescript.